package com.huike.business.service.impl;


import com.huike.business.domain.TbBusiness;
import com.huike.business.domain.TbBusinessTrackRecord;
import com.huike.business.domain.vo.BusinessTrackVo;
import com.huike.business.mapper.TbBusinessTrackRecordMapper;
import com.huike.business.service.ITbBusinessService;
import com.huike.business.service.ITbBusinessTrackRecordService;
import com.huike.common.utils.DateUtils;
import com.huike.common.utils.bean.BeanUtils;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 商机跟进记录Service业务层处理
 * 
 * @author wgl
 * @date 2021-04-28
 */
@Service
public class TbBusinessTrackRecordServiceImpl implements ITbBusinessTrackRecordService {

    @Autowired
    private TbBusinessTrackRecordMapper tbBusinessTrackRecordMapper;

    @Autowired
    private ITbBusinessService iTbBusinessService;

    /**
     * 添加商机跟进记录
     * @param businessTrackVo
     * @return
     */
    @Override
    public int addTrackRecord(BusinessTrackVo businessTrackVo) {

        //构建商机跟进对象并且将商机数据复制到商机跟进记录表中
        TbBusinessTrackRecord tbBusinessTrackRecord = new TbBusinessTrackRecord();
        BeanUtils.copyProperties(businessTrackVo,tbBusinessTrackRecord);
        //设置参数
        tbBusinessTrackRecord.setCreateTime(DateUtils.getNowDate());
        //执行持久层业务代码
        int row1 = tbBusinessTrackRecordMapper.addBusinessTrackRecord(tbBusinessTrackRecord);

        //构建商机对象
        TbBusiness tbBusiness = new TbBusiness();
        BeanUtils.copyProperties(businessTrackVo,tbBusiness);
        tbBusiness.setId(businessTrackVo.getBusinessId());

        //更新商机表数据
        int row2 = iTbBusinessService.updateTbBusiness(tbBusiness);

        return row1 + row2 > 1 ? 1 : 0;
    }

    /**
     * 根据商机id查询所有商机跟进记录
     * @param id
     * @return
     */
    @Override
    public List<TbBusinessTrackRecord> selectTrackRecordById(Long id) {
        return tbBusinessTrackRecordMapper.selectTrackRecordById(id);
    }
}
